/*   1:    */ package org.jetbrains.debugger;
/*   2:    */ 
/*   3:    */

import com.intellij.openapi.util.ActionCallback;
import com.intellij.openapi.util.ActionCallback.Chunk;
import com.intellij.openapi.util.AsyncResult;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.util.Consumer;
import com.intellij.util.EventDispatcher;
import com.intellij.util.containers.ConcurrentHashMap;
import com.intellij.util.containers.ConcurrentHashSet;
import gnu.trove.TObjectHashingStrategy;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Set;

/*   4:    */
/*   5:    */
/*   6:    */
/*   7:    */
/*   8:    */
/*   9:    */
/*  10:    */
/*  11:    */
/*  12:    */
/*  13:    */
/*  14:    */
/*  15:    */ 
/*  16:    */ public abstract class BreakpointManagerBase<T extends BreakpointBase<?>>
/*  17:    */   implements BreakpointManager
/*  18:    */ {
/*  19: 17 */   protected final Set<T> breakpoints = new ConcurrentHashSet();
/*  20: 18 */   protected final ConcurrentHashMap<T, T> breakpointDuplicationByTarget = new ConcurrentHashMap(new TObjectHashingStrategy()
/*  21:    */   {
/*  22:    */     public int computeHashCode(T paramAnonymousT)
/*  23:    */     {
/*  24: 21 */       int i = paramAnonymousT.getLine();
/*  25: 22 */       i = 31 * i + paramAnonymousT.getColumn();
/*  26: 23 */       if (paramAnonymousT.getCondition() != null) {
/*  27: 24 */         i = 31 * i + paramAnonymousT.getCondition().hashCode();
/*  28:    */       }
/*  29: 26 */       i = 31 * i + paramAnonymousT.getTarget().hashCode();
/*  30: 27 */       return i;
/*  31:    */     }
/*  32:    */     
/*  33:    */     public boolean equals(T paramAnonymousT1, T paramAnonymousT2)
/*  34:    */     {
/*  35: 32 */       return (paramAnonymousT1.getTarget().getClass() == paramAnonymousT2.getTarget().getClass()) && (paramAnonymousT1.getTarget().equals(paramAnonymousT2.getTarget())) && (paramAnonymousT1.getLine() == paramAnonymousT2.getLine()) && (paramAnonymousT1.getColumn() == paramAnonymousT2.getColumn()) && (StringUtil.equals(paramAnonymousT1.getCondition(), paramAnonymousT2.getCondition()));
/*  36:    */     }
/*  37: 18 */   });
/*  38: 40 */   protected final EventDispatcher<BreakpointManager.BreakpointListener> dispatcher = EventDispatcher.create(BreakpointManager.BreakpointListener.class);
/*  39:    */   
/*  40:    */   protected abstract T createBreakpoint(@NotNull BreakpointTarget paramBreakpointTarget, int paramInt1, int paramInt2, @Nullable String paramString, int paramInt3, boolean paramBoolean);
/*  41:    */   
/*  42:    */   protected abstract AsyncResult<Breakpoint> doSetBreakpoint(BreakpointTarget paramBreakpointTarget, T paramT);
/*  43:    */   
/*  44:    */   public Breakpoint setBreakpoint(@NotNull BreakpointTarget paramBreakpointTarget, int paramInt1, int paramInt2, @Nullable String paramString, int paramInt3, boolean paramBoolean)
/*  45:    */   {
/*  46: 48 */     if (paramBreakpointTarget == null) {
/*  47: 48 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/jetbrains/debugger/BreakpointManagerBase", "setBreakpoint" }));
/*  48:    */     }
/*  49: 48 */     final BreakpointBase localBreakpointBase1 = createBreakpoint(paramBreakpointTarget, paramInt1, paramInt2, paramString, paramInt3, paramBoolean);
/*  50: 49 */     BreakpointBase localBreakpointBase2 = (BreakpointBase)this.breakpointDuplicationByTarget.putIfAbsent(localBreakpointBase1, localBreakpointBase1);
/*  51: 50 */     if (localBreakpointBase2 != null) {
/*  52: 51 */       return localBreakpointBase2;
/*  53:    */     }
/*  54: 54 */     this.breakpoints.add(localBreakpointBase1);
/*  55: 55 */     if (paramBoolean) {
/*  56: 56 */       doSetBreakpoint(paramBreakpointTarget, localBreakpointBase1).doWhenRejected(new Consumer()
/*  57:    */       {
/*  58:    */         public void consume(@Nullable String paramAnonymousString)
/*  59:    */         {
/*  60: 59 */           ((BreakpointManager.BreakpointListener)BreakpointManagerBase.this.dispatcher.getMulticaster()).errorOccurred(localBreakpointBase1, paramAnonymousString);
/*  61:    */         }
/*  62:    */       });
/*  63:    */     }
/*  64: 63 */     return localBreakpointBase1;
/*  65:    */   }
/*  66:    */   
/*  67:    */   public ActionCallback remove(@NotNull Breakpoint paramBreakpoint)
/*  68:    */   {
/*  69: 69 */     if (paramBreakpoint == null) {
/*  70: 69 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/jetbrains/debugger/BreakpointManagerBase", "remove" }));
/*  71:    */     }
/*  72: 69 */     BreakpointBase localBreakpointBase = (BreakpointBase)paramBreakpoint;
/*  73: 70 */     boolean bool = this.breakpoints.remove(localBreakpointBase);
/*  74: 71 */     if (bool) {
/*  75: 72 */       this.breakpointDuplicationByTarget.remove(localBreakpointBase);
/*  76:    */     }
/*  77: 74 */     return (!bool) || (!localBreakpointBase.isVmRegistered()) ? ActionCallback.DONE : doClearBreakpoint(localBreakpointBase);
/*  78:    */   }
/*  79:    */   
/*  80:    */   @NotNull
/*  81:    */   public ActionCallback removeAll()
/*  82:    */   {
/*  83: 80 */     BreakpointBase[] arrayOfBreakpointBase1 = (BreakpointBase[])this.breakpoints.toArray(new BreakpointBase[this.breakpoints.size()]);
/*  84: 81 */     this.breakpoints.clear();
/*  85: 82 */     this.breakpointDuplicationByTarget.clear();
/*  86: 83 */     ActionCallback.Chunk localChunk = new ActionCallback.Chunk();
/*  87: 84 */     for (BreakpointBase localBreakpointBase : arrayOfBreakpointBase1) {
/*  88: 85 */       if (localBreakpointBase.isVmRegistered()) {
/*  89: 87 */         localChunk.add(doClearBreakpoint(localBreakpointBase));
/*  90:    */       }
/*  91:    */     }
/*  92: 90 */     ActionCallback tmp99_96 = localChunk.create();
/*  93: 90 */     if (tmp99_96 == null) {
/*  94: 90 */       throw new IllegalStateException(String.format("@NotNull method %s.%s must not return null", new Object[] { "org/jetbrains/debugger/BreakpointManagerBase", "removeAll" }));
/*  95:    */     }
/*  96: 90 */     return tmp99_96;
/*  97:    */   }
/*  98:    */   
/*  99:    */   protected abstract ActionCallback doClearBreakpoint(@NotNull T paramT);
/* 100:    */   
/* 101:    */   public void addBreakpointListener(@NotNull BreakpointManager.BreakpointListener paramBreakpointListener)
/* 102:    */   {
/* 103: 97 */     if (paramBreakpointListener == null) {
/* 104: 97 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/jetbrains/debugger/BreakpointManagerBase", "addBreakpointListener" }));
/* 105:    */     }
/* 106: 97 */     this.dispatcher.addListener(paramBreakpointListener);
/* 107:    */   }
/* 108:    */   
/* 109:    */   public Iterable<T> getBreakpoints()
/* 110:    */   {
/* 111:102 */     return this.breakpoints;
/* 112:    */   }
/* 113:    */   
/* 114:    */   protected final void notifyBreakpointResolvedListener(@NotNull T paramT)
/* 115:    */   {
/* 116:106 */     if (paramT == null) {
/* 117:106 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/jetbrains/debugger/BreakpointManagerBase", "notifyBreakpointResolvedListener" }));
/* 118:    */     }
/* 119:106 */     if (paramT.isResolved()) {
/* 120:107 */       ((BreakpointManager.BreakpointListener)this.dispatcher.getMulticaster()).resolved(paramT);
/* 121:    */     }
/* 122:    */   }
/* 123:    */ }



/* Location:           E:\idea\

 * Qualified Name:     org.jetbrains.debugger.BreakpointManagerBase

 * JD-Core Version:    0.7.0.1

 */